use std::collections::HashMap;


#[test]
fn test_jtools() {
    jtools::h1_say();
}

#[derive(Debug, Default)]
struct A {
    a: u8,
}

#[test]
fn test_def() { 
    let mut a: A = Default::default();
    a.a = 9;
    println!("{:?}", a);
}

#[test]
fn test_bin() {
    let a: u64 = 0x00000010;
    let s = jtools::binary::to_string_little(&a);
    println!("{}", s);
    let r = jtools::binary::to_string_big(&a);
    println!("{}", r);

    jtools::error::make_error("hello world");
}

#[test]
fn test_u8() {
    let a = 125u8;
    let b = a.abs_diff(3u8);

    println!("{} {}", b, a.count_ones());
}

#[test]
fn test_vec() {
    let mut a = Vec::<u8>::with_capacity(3);
    a.push(1);
    a.push(2);
    a.push(3);
    a.push(4);

    let b = a.iter();
    for i in b {
        println!("{}", i);
    }

}

#[test]
fn test_env() {
    let mut i: u8 = 0;
    for arg in std::env::args().skip(1) {
        i += 1;
        println!("{} {}", i, arg);
    }

    let byte_escape = "I'm saying hello \x7f";
    println!("{}", byte_escape);
}

const Test_Key:u32 = 15;

#[test]
fn test_base1() {
    let tup = (500, 6.4, 1);

    let (x, y, z) = tup;

    println!("The value of y is: {y}");
    let a = [1, 2, 3, 4, 5];
    
    let b = ["hello";2];
    println!("{:?} {:?}",a,b);

    // let s = String::from("hello");
}

#[test]
fn test_ref(){
    let a = 10;
    let b = &a;
    let c = b;
    println!("{} {}",b,c);

    let s1 = String::from("hello");
    let s2 = &s1;
    let s3 = "world";
    let s4 = &s1[0..=1];
}

#[test]
fn test_h1() {
    let ha = [1, 2];
    for item in &ha {
        println!("{}", item);
    }
}


#[test]
fn test_life() {
    let a = 1;
    let b = 2;
    let c = add(&a, &b);
    println!("{}", c);

    let s= "abc".to_string();
    let s1 = "d".to_string();
    let s2 = format!("{}{}",&s,&s1);
    println!("{}",s2);
    println!("{} {}",s,s1);


    let mut scores = HashMap::new();
    scores.insert(3, 1);
    scores.insert(1, 2);

    
}

#[test]
fn test_zip() {
    let a = vec!["a".to_string(),"b".to_string()];
    let b = vec![1,2];
    let c:HashMap<_,_>  = a.iter().zip(b.iter()).collect();
    println!("{:?}",c);
}

fn add<'a, 'b>(a: &'a i32, b: &'b i32) -> i32 {
    a + b
}



#[derive(Debug)]
struct User {
    name: String
}

impl User {
    fn new(name: &str) -> Self {
        User {
            name: name.to_string()
        }
    }
    fn fmt(&self) -> String {
        format!("User: {}",self.name)
    }
   
}
struct Color(i32, i32, i32);
struct AlwaysEqual;

#[test]
fn test_struct() {
    let u = User::new("hello");
    println!("{:?}",u);
    let c = 1;
    let a = Some(5);
    let d = match a {
        None => {
            println!("a is none");
            0
        },
        Some(i) => {
            println!("c is {}",c);
            println!("a is {}",i);
            1
        }
    };
    println!("d is {}",d);
    

}




